Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
Recibí un error: los objetos no son válidos como hijos de React (encontrado: [promesa de objeto])

Soy un poco nuevo en React. Y obtuve este error: los objetos no son válidos como hijos de React (encontrado: [objeto Promesa]). Y no estoy seguro de cómo solucionar este problema. ¿Pueden echar un vistazo? ¡Gracias!

Aquí está mi código.

 import React, { Component } from "react"; import "./App.css"; async function randomVerse() { const url = "https://labs.bible.org/api/?passage=random&type=json"; const passage = await fetch(url); const passageJson = await passage.json(); return passageJson; } const displayRandomVerse = async () => { let result = await randomVerse(); let verse = ""; verse += result[0].text; return verse; }; const returnVerse = displayRandomVerse(); class App extends Component { constructor() { super(); this.state = { verse: null }; } componentDidMount() { this.setState({verse: returnVerse}); }; render() { return ( <div className="App"> <h1>Good Morning, XXX!</h1> <h3>Bible verse : {this.state.verse} </h3> </div> ); } } export default App;
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Tienes que configurar await en const returnVerse = await displayRandomVerse(); . Esto debería darte el valor.

about 4 years ago · Juan Pablo Isaza Report

0

Debe buscar y esperar en su método componentDidMount

 async function randomVerse() { const url = "https://labs.bible.org/api/?passage=random&type=json"; const passage = await fetch(url); const passageJson = await passage.json(); return passageJson; } const displayRandomVerse = async () => { let result = await randomVerse(); let verse = ""; verse += result[0].text; return verse; }; class App extends Component { constructor() { super(); this.state = { verse: null }; } async componentDidMount() { //Notice changes in this section this.setState({verse: await displayRandomVerse()}); }; render() { return ( <div className="App"> <h1>Good Morning, XXX!</h1> <h3>Bible verse : {this.state.verse} </h3> </div> ); } } export default App;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!